#include "key.h"

uint8_t key_buff[3];
uint8_t lastkey_buff[3];
uint8_t keyFun_downFlag[5];

void key_music(void)
{
	if (key_buff[0] != lastkey_buff[0]) {
		buzz_didi(1);
	}
	
	if (key_buff[1] != lastkey_buff[1] && lastkey_buff[1] == 0) {
		buzz_didi(1);
	}
	
	if (key_buff[2] != lastkey_buff[2] && lastkey_buff[2] == 0) {
		
		uint8_t index = key_buff[2]-1;
		
		if (index < sizeof(keyFun_downFlag)) {
			keyFun_downFlag[index] = 1;
		}
		
		buzz_didi(1);
	}
	
	lastkey_buff[0] = key_buff[0];
	lastkey_buff[1] = key_buff[1];
	lastkey_buff[2] = key_buff[2];
}

/**
 * @brief  获取按键
 * @param  
 * @retval 无
 */
uint8_t fun_key_get(uint8_t num)
{
	
	if (num > sizeof(keyFun_downFlag)) {
		return 0;
	}
	
	if (keyFun_downFlag[num] == 1) {
		keyFun_downFlag[num] = 0;
		return 1;
	}
	
	return 0;
}

/**
 * @brief  获取按键
 * @param  
 * @retval 无
 */
uint8_t data_key_get_num(void)
{	
	if (key_buff[1] == 0) {
		return 0;
	}
	
	return 10 - key_buff[1];
}

/**
 * @brief  获取按键
 * @param  
 * @retval 无
 */
uint8_t data_key_get_bg(void)
{
	return key_buff[0];
}

/******************* (C) COPYRIGHT 2022 FUYEBING*****END OF FILE************/
